package cn.bugstack.domain.strategy.model.entity;

import cn.bugstack.types.common.Constants;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class RuleMatterEntity {
    /**
     * 用户ID
     * 判断是否是黑名单
     */
    private String userId;
    /**
     * 策略ID
     */
    private Long strategyId;
    /**
     * 抽奖奖品ID【规则类型为策略，则不需要奖品ID】
     */
    private Integer awardId;
    /**
     * 抽奖规则类型【rule_random - 随机值计算、rule_lock - 抽奖几次后解锁、rule_luck_award - 幸运奖(兜底奖品)】
     * 是需要根据这个查询规则值配置
     */
    private String ruleModel;

    public static void main(String[] args) {
        String ruleValue = "4000:102,103,104,105 5000:102,103,104,105,106,107 6000:102,103,104,105,106,107,108,109";
        Map<Long, String> ruleValueMap = new RuleMatterEntity().getAnalyticalValue(ruleValue);
        // {4000=4000:102,103,104,105, 6000=6000:102,103,104,105,106,107,108,109, 5000=5000:102,103,104,105,106,107}
        System.out.println(ruleValueMap);
    }
    private Map<Long, String> getAnalyticalValue(String ruleValue) {
        String[] ruleValueGroups = ruleValue.split(Constants.SPACE);
        Map<Long, String> ruleValueMap = new HashMap<>();
        for (String ruleValueKey : ruleValueGroups) {
            // 检查输入是否为空
            if (ruleValueKey == null || ruleValueKey.isEmpty()) {
                return ruleValueMap;
            }
            // 分割字符串以获取键和值
            String[] parts = ruleValueKey.split(Constants.COLON);
            if (parts.length != 2) {
                throw new IllegalArgumentException("rule_weight rule_rule invalid input format" + ruleValueKey);
            }
            ruleValueMap.put(Long.parseLong(parts[0]), ruleValueKey);
        }
        return ruleValueMap;
    }
}
